<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>组织管理</title>
	<meta name="decorator" content="default"/>
	<%@include file="/WEB-INF/views/include/treetable.jsp" %>
	<script type="text/javascript">
		$(document).ready(function() {
			
		});
		function page(n,s){
			$("#pageNo").val(n);
			$("#pageSize").val(s);
			$("#searchForm").submit();
        	return false;
        }
	</script>
</head>
<body style="overflow-y: auto;  height: 100%;">
	<%-- <ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/sys/office/list?id=${office.id}&parentIds=${office.parentIds}">组织列表</a></li>
		<shiro:hasPermission name="sys:office:edit"><li><a href="javascript:void(0);" onclick='opencreateWindow("/sys/office/form","新增",1000,500,"0px")'>新增</a></li></shiro:hasPermission>
	</ul> --%>
	<form:form id="searchForm" modelAttribute="office" action="${ctx}/sys/office/dialogOfficeList" method="post" class="breadcrumb form-search">
		<input id="pageNo" name="pageNo" type="hidden" value="${page.pageNo}"/>
		<input id="pageSize" name="pageSize" type="hidden" value="${page.pageSize}"/>
		<input id="id" name="id" type="hidden" value="${param.id }"/>
		<input id="type" name="parentIds" type="hidden" value="${param.parentIds}"/>
		<input id="type" name="type" type="hidden" value="${param.type }"/>
		<input id="isStop" name="isStop" type="hidden" value="${param.isStop }"/>
		
		<%-- <sys:tableSort id="orderBy" name="orderBy" value="${page.orderBy}" callback="page();"/> --%>
		<table class="t-search">
			<tr>
				<td style="width:120px;">公司/部门名称：</td>
				<td>
					<form:input path="name" htmlEscape="false" maxlength="225" class="input-search"/>
				</td>
				<td>
				</td>
				<td></td>			
				<td class="tb-btn">
					<input id="btn_search" class="btn btn-primary" type="submit" value="查询"/>
					<input type="button" id="reset_" class="reset btn" value="重置"/>
				</td>
			</tr>
		</table>
	</form:form>
	<sys:message content="${message}"/>
	<div class="css-tl">
		<table class="table table-striped table-bordered table-condensed" style="margin-bottom:-1px;">
			<thead>
			<tr>
				<th style="width:20px;"><input type="checkbox" class="checkall"/></th>
				<th style="width:300px;">公司/部门名称</th>
				<th style="width:80px;">编号</th>
				<th style="width:100px;">负责人</th>
				<th style="width:60px;">类型</th>
				<th style="width:60px;">资产总数</th>
				</tr></thead>
		</table>
		<table id="treeTable" class="table table-striped table-bordered table-condensed jqgrid-select">
			<tbody id="treeTableList">
				<c:forEach items="${page.list}" var="office">
					<tr id="{{row.id}}" pId="{{pid}}">
					<td style="width:20px;">
						<input type="checkbox"/>
						<input type="hidden" name="org_id" value="${office.id}"/>
						<input type="hidden" name="org_name" value="${office.name}"/>
						<input type="hidden" name="org_code" value="${office.code}"/>
						<input type="hidden" name="charge_user_id" value="${office.assetManagerId}"/>
						<input type="hidden" name="charge_user_name" value="${office.assetManagerName}"/>
						<input type="hidden" name="orgType" value="${office.type}"/>
						<input type="hidden" name="orgTypeName" value="${office.typeName}"/>
						<input type="hidden" name="assetForCompanyCount" value="${office.assetForCompanyCount}"/>
						<input type="hidden" name="assetForOrgCount" value="${office.assetForOrgCount}"/>
					</td>
					<td style="width:300px;">${office.name}</td>
					<td style="width:80px;" class="center">${office.code}</td>
					<td style="width:100px;" class="center">${office.assetManagerName}</td>
					<td style="width:60px;" class="center">${office.typeName}</td>
					<c:if test="${office.type=='1'}">
						<td style="width:60px;" class="center">${office.assetForCompanyCount}</td>
					</c:if>
					<c:if test="${office.type=='2'}">
						<td style="width:60px;" class="center">${office.assetForOrgCount}</td>
					</c:if>
				</tr>
				</c:forEach>
			</tbody>
		</table>
		<div class="pagination">${page}</div>
	</div>
	
	<script type="text/javascript">
		/* add for lxh 20160309
		url :url /allAsset/dialogCategoryIndex
		title:标题
		width：宽度
		height：高度
		top：窗口离顶部的距离,可以是百分比或像素(如 100px)
		use:打开新增窗口
		*/
		 function opencreateWindow(url,title,width,height,topValue){
			url ="iframe:"+"${ctx}/"+url;
			topValue = (topValue =='' ? '10%':'10px');
			top.$.jBox.open(url, title, width, height, { 
				persistent: true, 
				top:topValue,
				buttons: {},submit:function(v,h,f){
				 /*  点击窗口按钮后的回调函数，返回true时表示关闭窗口，参数有三个，
					 v表示所点的按钮的返回值，
					 h表示窗口内容的jQuery对象，
					 f表示窗口内容里的form表单键值
				  */
				},
				closed: function () { 
					/* 窗口关闭后执行的函数 */
					var istrue=$('#closedwindow', window.parent.parent.document).val();
					if(istrue=="true"){
						$('#closedwindow', window.parent.document).val("false");
						parent.window.location.reload();
					}
				}
			});
		} 
	</script>
	
	<script>
		var selects=true; //false 单选   true 可以多选
		
		selectCheckBox();
		function selectCheckBox(){
			if(selects){
				$(".checkall").removeAttr("disabled");
			}else{
				$(".checkall").attr("disabled","disabled");
			}
			
			$(".jqgrid-select tbody>tr").click(function(){
				$(".checkall").removeAttr("checked");
				var attrId=$(this).find("td:eq(0) input[name=charge_user_id]").val();
				var orgName=$(this).find("td:eq(0) input[name=org_name]").val();
				if(attrId=="" || attrId==null || attrId==undefined){
					$.jBox.tip("请设置【"+orgName+"】的资产管理员",'',{timeout:500});
					return false;
				}
				if(selects){
					if($(this).hasClass("jdselect")){
						$(this).removeClass("jdselect");
						$(this).find("td:eq(0) input[type=checkbox]").removeAttr("checked");
					}else{
						$(this).addClass("jdselect");
						$(this).find("td:eq(0) input[type=checkbox]").attr("checked","true");
					}
				}else{
					$(this).addClass("jdselect");
					$(this).find("td:eq(0) input[type=checkbox]").attr("checked","true");
					$(this).siblings().removeClass("jdselect");
					$(this).siblings().find("td:eq(0) input[type=checkbox]").removeAttr("checked");
				}
				
				//新增标签
				addlabe($(this));
			});
			
			
			//全选
			$(".checkall").click(function(){
				if($(this).is(":checked")){
					$(this).parents("table").next().find("tr:gt(0)").addClass("jdselect");
					$(this).parents("table").next().find("tr:gt(0)").find("td:eq(0) input[type=checkbox]").attr("checked","true");
					
					allselecttr();
				}else{
					$(this).parents("table").next().find("tr:gt(0)").removeClass("jdselect");
					$(this).parents("table").next().find("tr:gt(0)").find("td:eq(0) input[type=checkbox]").removeAttr("checked");
					
					allselecttr()
				}
			});
			
			//强制去掉列表列表contents页滚动条
			$(function(){
				$(document).find("html").removeAttr("style");
				$(document).find("html").css({"overflow":"hidden"});
			});
		}
		
		//全选tr且生成小标签
		function allselecttr(){
			$("#content",parent.document).find(".jszcselect>span").remove();
			var selecttrs=$(".jqgrid-select").find("tbody>tr");
			$.each(selecttrs,function(count,event){
				addlabe($(event));
			});
		}
		
		//生成标签
		function addlabe(event){
			var parentiFrame=$("#content",parent.document).find(".jszcselect");
			var org_id=event.find("td:eq(0) input[name=org_id]").val();
			var org_name=event.find("td:eq(0) input[name=org_name]").val();
			var org_code=event.find("td:eq(0) input[name=org_code]").val();
			var charge_user_id=event.find("td:eq(0) input[name=charge_user_id]").val();
			var charge_user_name=event.find("td:eq(0) input[name=charge_user_name]").val();
			var orgType=event.find("td:eq(0) input[name=orgType]").val();
			var orgTypeName=event.find("td:eq(0) input[name=orgTypeName]").val();
			var assetForCompanyCount=event.find("td:eq(0) input[name=assetForCompanyCount]").val();
			var assetForOrgCount=event.find("td:eq(0) input[name=assetForOrgCount]").val();
			
			//生成标签
			if(!event.hasClass("jdselect")){
				parentiFrame.find("#s_"+org_id).remove();
			}else{
				//判断是否已经选择了组织标签
				var spans=parentiFrame.find("span");
				var isTrue=false;
				$.each(spans,function(index,event){
					var id=$(event).find("input[name=org_id]").val()
					if(id==org_id){
						isTrue=true;
					}
				});
				if(isTrue)return false;
				//生成标签
				var html=
				"<span id='s_"+org_id+"'>"+org_name+"<i>×</i>"+
				"<input type='hidden' name='org_id' value='"+org_id+"'/>"+
				"<input type='hidden' name='org_name' value='"+org_name+"'>"+
				"<input type='hidden' name='org_code' value='"+org_code+"'>"+
				"<input type='hidden' name='charge_user_id' value='"+charge_user_id+"'>"+
				"<input type='hidden' name='charge_user_name' value='"+charge_user_name+"'>"+
				"<input type='hidden' name='orgType' value='"+orgType+"'>"+
				"<input type='hidden' name='orgTypeName' value='"+orgTypeName+"'>"+
				"<input type='hidden' name='assetForCompanyCount' value='"+assetForCompanyCount+"'>"+
				"<input type='hidden' name='assetForOrgCount' value='"+assetForOrgCount+"'>"+
				"</span>";
				parentiFrame.append(html);
				//触发删除按钮；
				removeLabel();
			}
		}
		
		function removeLabel(){
			var parentiFrame=$("#content",parent.document).find(".jszcselect");
			parentiFrame.find("span>i").click(function(){
				var id=$(this).parents("span").find("input[name=org_id]").val();
				$(this).parents("span").remove();	
				
				var tr=$("#treeTableList").find("input[value="+id+"]").parents("tr");
				tr.removeClass("jdselect");
				tr.find("td:eq(0)").find("input[type=checkbox]").removeAttr("checked");;
			});
		}
		
	</script>
	
</body>
</html>